import os
from dish_manager import root, load_all_dishes_from_file, save_all_dishes_to_file
from storage_manager import load_all_dishes_from_file, save_all_dishes_to_file


def main():
    """主函数：启动图形化菜品管理界面"""
    # 确保数据目录存在
    if not os.path.exists("data"):
        os.makedirs("data")

    # 加载菜品数据
    all_dishes = load_all_dishes_from_file()

    # 绑定窗口关闭事件以保存数据
    def on_closing():
        save_all_dishes_to_file(all_dishes)
        root.destroy()

    root.protocol("WM_DELETE_WINDOW", on_closing)

    # 启动图形化界面
    root.mainloop()


# 程序入口
if __name__ == "__main__":
    main()